package com.itrencai.d4_date.regex;

import javafx.css.Match;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexDemo3paqu {
    public static void main(String[] args) {
        String rs="跟着一起学java，电话020-43433434，或者联系邮箱"+
                "itcast@itcast.cn,电话18762832633,0203232323"+
                "邮箱bozai@itcast.cn,400-100-3233,4001003232";

    //需求：从上面的内容中爬取处电话号码和邮箱
    //1.定义爬取规则，字符串形式 爬取邮箱 手机号码 电话号码
    String regex="(\\w{1,30}@[a-zA-Z0-9]{2,20}(\\.[a-zA-Z0-9]{2,20}){1,2})|(1[3-9]\\d{9})"+
            "|(0\\d{2,6}-?\\d{5,20})|(400-?\\d{3,9}-?\\d{3,9})";

    //2.把这个爬取规则编译成匹配对象
    Pattern pattern =Pattern.compile(regex);

    //3.得到一个内容匹配器对象
    Matcher matcher =pattern.matcher(rs);

    //4.开始找了
        while (matcher.find()) {
            String rs1=matcher.group();
            System.out.println(rs1);
        }


    }
}
